package com.jsy.imagespickerrroject;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.jsy.imagepicker.ImagePicker;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.bt_picker).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImagePicker.from(MainActivity.this)
                        .setMaxCount(9)
                        .setSpanCount(4)
                        .setUseCamera(true)
                        .setCut(true)
                        .setCutSize(600,600)
                        .setCutAspect(2,1)
                        .setFilterGif(true)
                        .start(2);
            }
        });
        findViewById(R.id.bt_pre).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityCompat.requestPermissions(
                        MainActivity.this,
                        new String[]{
                                Manifest.permission.CAMERA,
                                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                                Manifest.permission.READ_EXTERNAL_STORAGE
                        },1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (RESULT_OK == resultCode && requestCode == 2){
            ArrayList<String> list = (ArrayList<String>) data.getSerializableExtra("imagesList");
            Log.e("选择的图片",list.toString());
            ImageView iv =findViewById(R.id.iv);
            iv.setImageURI(Uri.parse(list.get(0)));
        }
    }
}
